package com.soulkun.smarthome.ui.main.scene.adapter

import android.content.Context
import androidx.databinding.ObservableArrayList
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.LinearLayoutManager
import com.soulkun.smarthome.R
import com.soulkun.smarthome.databinding.AppRecycleItemMainSceneAutoListBinding
import com.soulkun.smarthome.logic.enum.ExpressionEnum
import com.soulkun.smarthome.logic.model.AutoData
import com.soulkun.smarthome.logic.model.ExpressionModel
import soulkun.library.helper.decoration.LinearSpaceItemDecorationHelper
import soulkun.library.mvvm.adapter.BaseDataBindingRecyclerViewAdapter

class AppMainSceneAutoListAdapter(context: Context, dataList: ObservableArrayList<AutoData>) :
    BaseDataBindingRecyclerViewAdapter<AutoData>(context, dataList) {

    override fun getContentLayoutResId(): Int {
        return R.layout.app_recycle_item_main_scene_auto_list
    }

    override fun setContentViewHolderCreateListener(binding: ViewDataBinding) {
    }

    override fun setContentViewHolderBindListener(binding: ViewDataBinding, dataPosition: Int) {
        val data = dataList[dataPosition]
        var sceneName = "如果 "
        data.condition.forEach {
            sceneName += " ${it.conditionName}"
        }
        (binding as AppRecycleItemMainSceneAutoListBinding).tvMainSceneAutoListTextAutoName.text =
            sceneName
        binding.tvMainSceneAutoListTextAutoJob.text = "${data.job.size}个任务"
        val expressionList = ObservableArrayList<ExpressionModel>()
        expressionList.addAll(data.condition.map {
            ExpressionModel(ExpressionEnum.Condition, it.conditionId)
        })
        expressionList.add(ExpressionModel(ExpressionEnum.To, 0))
        expressionList.addAll(data.job.map {
            ExpressionModel(ExpressionEnum.Job, it.jobId)
        })
        binding.rvMainSceneAutoListListExpression.layoutManager =
            LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
        binding.rvMainSceneAutoListListExpression.adapter =
            AppMainSceneAutoExpressionListAdapter(context, expressionList)
        binding.rvMainSceneAutoListListExpression.addItemDecoration(LinearSpaceItemDecorationHelper(0,0,0,0,10))

    }

}